package com.hunan.yllxy.repostitory.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hunan.yllxy.repostitory.entity.UserInfo;
import com.hunan.yllxy.repostitory.mapper.UserInfoMapper;
import com.hunan.yllxy.repostitory.dao.UserInfoDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hunan.yllxy.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘华
 * @since 2025-06-16
 */
@Service
public class UserInfoDaoImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoDao {
    @Override
    public UserInfo findByAccount(String username) {
        if (StringUtils.isNull(username)) {
            return null;
        }
        LambdaQueryWrapper<UserInfo> wrapper = Wrappers.lambdaQuery(UserInfo.class);
        wrapper.eq(UserInfo::getAccount, username.trim());
        List<UserInfo> userInfos = baseMapper.selectList(wrapper);
        if (userInfos.size() > 0) {
            return userInfos.get(0);
        } else {
            return null;
        }
    }

    @Override
    public List<UserInfo> findByRole(String roleId) {
        return baseMapper.findByRole(roleId);
    }

    @Override
    public Page<UserInfo> findByRolePageQuery(String roleId, Page<UserInfo> page) {
        return baseMapper.findByRolePageQuery(roleId,page);
    }
}
